package test00.lx07;

import java.util.stream.Stream;

/**
 * @author ZQX
 * @date 2025-04-09
 */
public class MainTest01 {
    public static void main(String[] args) {
        // 第一：定义数据源 - 数组、集合
        Student[] students = {
                new Student("李三", 18),
                new Student("张四", 8),
                new Student("李三三", 28),
                new Student("李三四", 38),
                new Student("李三五", 48),
                new Student("李三六", 88),
                new Student("刘七", 68),
        };

        // 第二：基于集合或数组创建流对象
        Stream<Student> stream = Stream.of(students);

        // 第三：基于流对象相关的API方法，实现相关的操作
        // boolean test(T t);
        Stream<Student> nameStream = stream
                .filter(stu -> stu.getName().startsWith("李"));

        Stream<Student> ageStream = nameStream.filter(stu -> stu.getAge() > 18);

        Stream<Student> sortedStream = ageStream
                .sorted((stu1, stu2) -> stu2.getAge() - stu1.getAge());

        // R apply(T t);
        Stream<String> usernameStream = sortedStream.map(Student::getName);

        Stream<String> limitStream = usernameStream.limit(2);

        limitStream.forEach(System.out::println);


    }
}
